package com.eb.controller;

import com.eb.client.UserClient;
import com.eb.pojo.*;
import com.eb.service.KjService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("kj")
@CrossOrigin
public class KjController {
    @Autowired
    private KjService kjService;
    @Autowired
    private UserClient userClient;
    @GetMapping
    public List<BargainGoods> list(){
        return kjService.list();
    }
    @GetMapping("/shop")
    public  List<Map<String,Object>>  shop(){
        List<Map<String,Object>> list= kjService.shop();
        return list;
    }
    @GetMapping("/{id}")
    public Map<String,Object> findById(@PathVariable("id")int id){
        return kjService.findById(id);
    }
    @GetMapping("redis/{id}")
    public List<BigDecimal> kanjia(@PathVariable("id")long id){

          return kjService.kanjia(id);
    }
    @PostMapping("kjGoods")
    public Result kjGoods(@RequestBody Also also){
           return kjService.kjGoods(also);
    }

    @GetMapping("redis/get")
    public void redisget(){
        kjService.redisget();
    }
    @GetMapping("redis/list")
    public void redislist(){
        kjService.redislist();
    }
    @GetMapping("also/list")
    public  List<Map<String,Object>> alsoList(){
        List<Map<String,Object>> mapList=  new ArrayList<Map<String, Object>>();
        List<Also> list = kjService.alsoList();
        for (Also also : list) {
            Map<String, Object> map = new HashMap<>();
            MiaoshaUser byId = userClient.findById(also.getUserid());
            map.put("userid",byId.getId());
            map.put("username",byId.getNickname());
            map.put("goodsname",also.getGoodsname());
            map.put("id",also.getId());
            map.put("price",also.getPrice());
            map.put("bid",also.getBid());
            mapList.add(map);
        }
        return mapList;
    }
    @PutMapping("kanyidao/{id}")
    public Object kanyidao(@PathVariable("id")Long id){
       return  kjService.kanyidao(id);
    }
}
